
<script>
    $(function(){
        var satisfy0 = [
            "1分很不满意",
            "2分不满意",
            "3分一般",
            "4分满意",
            "5分很满意"
        ];
        var match0 = [
            "大于80分钟",
            "60分钟~80分钟",
            "40分钟~60分钟",
            "20分钟~40分钟",
            "20分钟以内"
        ];
        
        var match1 = [
            "太难吃了，下次绝不会再点",
            "一般般，总感觉差点什么",
            "还可以，味道中规中矩",
            "蛮好吃，下次还想点哦",
            "超赞，实在太好吃啦"
        ];
        var match2 = [
            "不够吃，又要点一份了",
            "有点少，下次多加点米吧",
            "刚刚好，不多不少不浪费",
            "足够多，吃完肚子饱饱的",
            "太多啦，要撑到啦"
        ];
        var div = $('#table_comment').find('img');
        div.hover(function(){
            var index = $(this).index();
            var box = $(this).parent('td').children('img');
            for(var i=0;i<5;i++){
                if(index < i){
                    box.eq(i).attr("src","__PUBLIC__/images/star_gray.png");
                }else{
                    if(index<2){
                        box.eq(i).attr("src","__PUBLIC__/images/star_hover.png");
                    }else{
                        box.eq(i).attr("src","__PUBLIC__/images/star_gold.png");
                    }
                }
            }
            var tr_index = $(this).parent('td').parent('tr').index();
            var left = $(this).offset().left;
            var top = $(this).offset().top;
            
            var satisfy_word,match_word = '';
            if(tr_index == 1){
                match_word = match1[index];
            }else if(tr_index ==2){
                match_word = match2[index];
            }else{
               
                match_word = match0[index];
            }
            satisfy_word = satisfy0[index];
            var tip = "<div class='tip'id='tip'><span id='points'class='points'>"+satisfy_word+"</span><div id='pointsinfo' class='pointsinfo'>"+match_word+"</div></div>";
            $('#tiparea').html(tip);
            $('#tip').css({"left":left,"top":top+25});
        },function(){
            $('#tiparea').empty();
            var clicknum = $(this).parent('td').attr("clicknum");
            var box = $(this).parent('td').children('img');
            var index= $(this).index();
            for(var j = 0;j<5;j++){
                if(clicknum >j){
                    box.eq(j).attr("src","__PUBLIC__/images/star_gold.png");
                }else{
                    box.eq(j).attr("src","__PUBLIC__/images/star_gray.png");
                }
            }
            if(clicknum == 1){
                box.eq(0).attr("src","__PUBLIC__/images/star_hover.png");
            }
            if(clicknum == 2){
                box.eq(0).attr("src","__PUBLIC__/images/star_hover.png");
                box.eq(1).attr("src","__PUBLIC__/images/star_hover.png");
            }
          
        })
        div.click(function(){
            var index = $(this).index();
            var box = $(this).parent('td').children('img');
            for(var i=0;i<=index;i++){
                if(index >1){
                    box.eq(i).attr("src","__PUBLIC__/images/star_gold.png");
                }else{
                    box.eq(i).attr("src","__PUBLIC__/images/star_hover.png");
                }
            }
            var tr_index = $(this).parent('td').parent('tr').index();
            if(tr_index == 1){
                $('#tip'+tr_index+'').html("<strong>"+parseInt(index+1)+"分</strong> - "+match1[index]+"");
                
                    $("#commenttext").val(match1[index]);
                
                
            }else if(tr_index ==2){
                $('#tip'+tr_index+'').html("<strong>"+parseInt(index+1)+"分</strong> - "+match2[index]+"");
            }else{
                $('#tip'+tr_index+'').html("<strong>"+parseInt(index+1)+"分</strong> - "+match0[index]+"");
            }
            $(this).parent('td').attr("clicknum",parseInt(index+1));
        })

    })
    function comment_count(v){
        var len = v.length;
        $('#word_counter').text(500-len);
    }
    function saveComment(id){
        var full = $("#full").attr("clicknum");
        var speed = $("#speed").attr("clicknum");
        var delicious = $("#delicious").attr("clicknum");
       var  comment = $("#commenttext").val();
        if(comment == ''){
            showTip('系统提示',"评价内容不能为空",'2',1.5,'',0);
            return false;
        }
        $.post("{:U('Ajax/saveComment')}",{
            id:id,
            full:full,
            speed:speed,
            delicious:delicious,
            comment:comment
        },function(data){
            if(data  == -1){
                showTip('系统提示',"已评价！",'2');
            }else{
                var points = "{$config['points_comment']}";
            closebgbox('#mainbox');
            showTip('系统提示',"评价成功,获得"+points+"积分！",'1',1.5,'',-1);
            }
            
        })
    }
</script>


<div id="browsebox" class="browsebox"style="width:600px;" >
    <div class="head" id="headbox">
        <a class="close" onclick="closebgbox('#mainbox')"></a>
        <span id="title">餐厅点评</span>
    </div>

    <div class='content' style="padding:20px 10px">
      
            <table class="flight_table" cellSpacing="0" cellPadding="0" width="100%">
                <tbody>

                    <tr>
                        <td width="120px" style="text-align:center">点评餐厅：</td>
                        <td class="table_left" id="shop_name">
                         
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:center">服务打分：</td>
                        <td class="table_left">
                            <table class="table_comment"id="table_comment">
                                <tr>
                                    <td width="60px">送餐速度</td>
                                    <td width="120px" class="imglist" id="speed">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                    </td>
                                    <td class="td_com_word"id="tip0"></td>
                                </tr>
                                <tr>
                                    <td width="60px">口味</td>
                                    <td width="120px" class="imglist" id="delicious">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                    </td>
                                    <td class="td_com_word"id="tip1"></td>
                                </tr>
                                <tr>
                                    <td width="60px">份量</td>
                                    <td width="120px" class="imglist" id="full">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                        <img src="__PUBLIC__/images/star_gray.png">
                                    </td>
                                    <td class="td_com_word" id="tip2"></td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:center">评价内容：</td>
                        <td class="table_left">
                            <div class="cbox_text">
                                <textarea class="cbox_msg"maxlength="500" onkeyup="comment_count(this.value)" name="comment"id="commenttext"autocomplete="off"></textarea>
                                <p>还可以输入<strong class="word_counter" id="word_counter">500</strong>字</p>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="table_right"></td>
                        <td class="table_left">
                            <p style="margin:20px 0 0">
                                <input class="orange_btn" type="button" onclick="saveComment('{$id}')" value="保存">
                                <a id="address_cancel" class="cancel_btn" onclick="closebgbox('#mainbox')" href="javascript:;">取消</a>
                            </p>
                        </td>
                    </tr>

                </tbody>
            </table>
      
    </div>
</div>

